package thread;

// 死锁
public class ThreadDemo22 {
    public static void main(String[] args) {
        Object A = new Object();
        Object B = new Object();
        Thread t1 = new Thread(()->{
            synchronized (A) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t1");
                synchronized (B) {
                    System.out.println("t11");
                }
            }
        });
        Thread t2 = new Thread(()->{
            synchronized (A){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t2");
                synchronized (B){
                    System.out.println("t22");
                }
            }
        });

        t1.start();
        t2.start();
    }
}
